package com.th.supcom.pds.phamapply.client.widget.phamapplydetail;

import java.util.ArrayList;
import java.util.List;

import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
import com.extjs.gxt.ui.client.store.ListStore;
import com.extjs.gxt.ui.client.widget.grid.ColumnConfig;
import com.extjs.gxt.ui.client.widget.grid.ColumnData;
import com.extjs.gxt.ui.client.widget.grid.ColumnModel;
import com.extjs.gxt.ui.client.widget.grid.Grid;
import com.extjs.gxt.ui.client.widget.grid.GridCellRenderer;
import com.th.supcom.pds.common.client.widget.PdsGrid;
import com.th.supcom.pds.common.utils.ClientUtils;
import com.th.supcom.pds.phamapply.client.model.InpPhamApplyDetailSummaryModel;

/**
 * 本次领药药品Grid
 */
public class PhamApplyCurrentApplyGrid extends PdsGrid <InpPhamApplyDetailSummaryModel>
{
    public PhamApplyCurrentApplyGrid ()
    {
        setHeaderVisible (true);
        setHeading ("本次请领药品");
    }

    @Override
    public ColumnModel createColumnModel ()
    {
        List <ColumnConfig> configs = new ArrayList <ColumnConfig> ();
        ColumnConfig column = null;
        column = new ColumnConfig ("color", "", 20);
        column.setRenderer (ClientUtils.getSummaryStockEnoughRenderer ());
        configs.add (column);
        column = new ColumnConfig ("phamName", "药品名称", 150);
        configs.add (column);
        column = new ColumnConfig ("phamSpec", "规格", 150);
        configs.add (column);
        column = new ColumnConfig ("detailSumAmount", "包装数量", 80);
        column.setAlignment (HorizontalAlignment.RIGHT);
        column.setRenderer (getSumAmountRenderer ());
        configs.add (column);
        return new ColumnModel (configs);
    }

    /**
     * 获取摆药数量
     * 
     * @return
     */
    private GridCellRenderer <InpPhamApplyDetailSummaryModel> getSumAmountRenderer ()
    {
        return new GridCellRenderer <InpPhamApplyDetailSummaryModel> ()
        {

            @Override
            public Object render (InpPhamApplyDetailSummaryModel model, String property, ColumnData config, int rowIndex, int colIndex,
                                  ListStore <InpPhamApplyDetailSummaryModel> store, Grid <InpPhamApplyDetailSummaryModel> grid)
            {
                return model.getDetailSumAmount () + model.getDosageUnit ();
            }
        };
    }
}
